package com.liu.dw.controller.word;

import com.liu.dw.common.word.WordUtils;
import com.liu.dw.service.word.WordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @version 1.0
 * @author： LiuWeiGang
 * @date： 2021-12-03 16:50
 * 重构文档管理系统
 */



@Slf4j
@Api(value="word文档上传",tags = "word文档上传")
@RestController
@RequestMapping("/implunt")
public class WordController {

    @Autowired
    private WordService wordService;

    /**
     * 按段落解析一个word文档
     * @param file
     * @throws Exception
     */
    @ApiOperation(value="word文档上传解析", notes="word文档上传解析")
    @RequestMapping(value = "upload", method = RequestMethod.POST)
    public void uploadFile(@RequestParam(value = "file", required = true) MultipartFile file) throws IOException {
         if (file == null || file.isEmpty()) {
             return;
         }
        String textFileName=file.getOriginalFilename();
        String suffix = textFileName.substring(textFileName.lastIndexOf("."));
            //判断如果是 .docx 的文件解析
            if (suffix.endsWith(".docx")) {
                wordService.uploadFile(file);
            }else {
                wordService.uploadFile(file);
            }
    }
}
